import { Body, Controller, Get, Post, Request, UseGuards } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { AuthService } from './auth.service';
import { WeChatDto } from './auth.dto';
import { Authorize } from 'src/core/decorators/index.decorator';
import { AuthGuard } from '@nestjs/passport';
import { CURRENT_USER } from 'src/core/contants';

@ApiTags('登录模块')
@Controller('auth')
export class AuthController {
  constructor(private authService: AuthService) {}

  @Post('company/login')
  @Authorize()
  @ApiOperation({ summary: '企业登录' })
  async companyLogin(@Body() data: WeChatDto): Promise<{ token: string }> {
    return await this.authService.company(data);
  }

  @Post('student/login')
  @Authorize()
  @ApiOperation({ summary: '学生登录' })
  async studentLogin(@Body() data: WeChatDto): Promise<{ token: string }> {
    return await this.authService.student(data);
  }

  @Get('logout')
  @ApiOperation({summary: '退出登录'})
  async logout(@Request() req) {
    return await this.authService.logout(req[CURRENT_USER].uid)
  }

  @Post('admin/login')
  @ApiOperation({ summary: '后台登录' })
  @UseGuards(AuthGuard('local'))
  @Authorize()
  async adminLogin(@Request() req) {
    return await this.authService.login(req.user);
  }
}
